package cn.edu.xjtu.daily.April.day_4_15;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author Hydrion-QLz
 * @date 2022-04-15 18:48
 * @description 提高组  Getting Zero https://codeforces.com/contest/1661/problem/B
 */
public class Main2 {
    static int num = 32768;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = getList();

        for (int i = 0; i < n; i++) {
            int idx = sc.nextInt();
            System.out.print(arr[idx] + " ");
        }
        sc.close();
    }

    private static int[] getList() {
        int[] arr = new int[num + 1];
        Arrays.fill(arr, Integer.MAX_VALUE);
        arr[0] = 0;
        Deque<Integer> queue = new LinkedList<>();
        queue.addLast(0);
        while (!queue.isEmpty()) {
            int val = queue.removeFirst();
            int temp = (val - 1 + num) % num;
            if (arr[val] + 1 < arr[temp]) {
                arr[temp] = arr[val] + 1;
                queue.addLast(temp);
            }

            if (val % 2 == 0) {
                int m = val == 0 ? num : 0;
                temp = (m / 2) % num;
                if (arr[val] + 1 < arr[temp]) {
                    arr[temp] = arr[val] + 1;
                    queue.addLast(temp);
                }
            }

        }
        return arr;
    }
}
